with GWindows.GStrings; use GWindows.GStrings;

with Ada.Calendar;
package body time is

  function hour (t: in Ada.Calendar.Time) return GWindows.GString is
    Hour_str: GWindows.GString(1..2);

    Any:  Ada.calendar.Year_Number;
    Mes:  Ada.calendar.Month_Number;
    Dia:  Ada.calendar.Day_Number;
    Segs: Ada.calendar.Day_Duration;
    Hora: Integer;

    s: GWindows.GString(1..3);
  begin
    Ada.calendar.Split(t, Any, Mes, Dia, Segs);

    Hora:=   Integer(Segs)/3600;

    if Hora<10
      then s(1..2):= To_GString_From_String (integer'image(Hora));
           Hour_str(1..2):='0' & s(2..2);
      else s(1..3):= To_GString_From_String (integer'image(Hora));
           Hour_str(1..2):= s(2..3);
    end if;
    Return Hour_str;
  end hour;

  function minute (t: in Ada.Calendar.Time) return GWindows.GString is
    Min_str: GWindows.GString(1..2);

    Any:  Ada.calendar.Year_Number;
    Mes:  Ada.calendar.Month_Number;
    Dia:  Ada.calendar.Day_Number;
    Segs: Ada.calendar.Day_Duration;
    Hora, Mini: Integer;

    s: GWindows.GString(1..3);
  begin
    Ada.calendar.Split(t, Any, Mes, Dia, Segs);

    Hora:=   Integer(Segs)/3600;
    Mini:=    (Integer(Segs)/60)-(60*Hora);

    if Mini<10
      then s(1..2):= To_GString_From_String (integer'image(Mini));
           Min_str(1..2):='0' & s(2..2);
      else s(1..3):= To_GString_From_String (integer'image(Mini));
           Min_str(1..2):= s(2..3);
    end if;
    Return Min_str;
  end minute;

  function second (t: in Ada.Calendar.Time) return GWindows.GString is
    Sec_str: GWindows.GString(1..2);

    Any:  Ada.calendar.Year_Number;
    Mes:  Ada.calendar.Month_Number;
    Dia:  Ada.calendar.Day_Number;
    Segs: Ada.calendar.Day_Duration;
    Hora, Min, Segons: Integer;

    s: GWindows.GString(1..3);
  begin
    Ada.calendar.Split(t, Any, Mes, Dia, Segs);

    Hora:=   Integer(Segs)/3600;
    Min:=    (Integer(Segs)/60)-(60*Hora);
    Segons:= Integer(Segs)-(60*Min+3600*Hora);

    if Segons<10
      then s(1..2):= To_GString_From_String (integer'image(Segons));
           Sec_str(1..2):='0' & s(2..2);
      else s(1..3):= To_GString_From_String (integer'image(Segons));
           Sec_str(1..2):= s(2..3);
    end if;
    Return Sec_str;
  end second;
end time;
